package com.android.commcount.ui.fragment;

import android.content.Intent;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.android.baselibrary.interface_.CommCallBack;
import com.android.baselibrary.ui.BaseFragment;
import com.android.baselibrary.view.MultiStateView;
import com.android.commcount.R;
import com.android.commcount.R2;
import com.android.commcount.adapter.Home_CountHistoryAdapter;
import com.android.commcount.bean.Count_DetailInfo;
import com.android.commcount.manager.SqlHelper;
import com.android.commcount.ui.activity.CommCount_CountEditActivity;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;

import butterknife.BindView;

public class CountHistoryFragment extends BaseFragment {

    @BindView(R2.id.multiplestatusView)
    MultiStateView multiplestatusView;
    @BindView(R2.id.recyclerview)
    RecyclerView recyclerview;
    @BindView(R2.id.smartrefreshlayout)
    SmartRefreshLayout smartrefreshlayout;

    Home_CountHistoryAdapter adapter;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_onlylist;
    }

    @Override
    protected void initView() {
        multiplestatusView.setViewState(MultiStateView.ViewState.LOADING);
        multiplestatusView.setOnRetryListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                multiplestatusView.setViewState(MultiStateView.ViewState.LOADING);
                getData();
            }
        });

        recyclerview.setLayoutManager(new LinearLayoutManager(mContext));
        adapter = new Home_CountHistoryAdapter(mContext, onItemClick);
        recyclerview.setAdapter(adapter);

        smartrefreshlayout.setEnableRefresh(false);
        smartrefreshlayout.setEnableLoadMore(false);
    }

    CommCallBack onItemClick = new CommCallBack() {
        @Override
        public void onResult(Object obj) {
            Count_DetailInfo countDetailInfo = (Count_DetailInfo) obj;
            Intent intent = new Intent(mContext, CommCount_CountEditActivity.class);
            intent.putExtra("editTime", countDetailInfo.editTime);
            startActivity(intent);
        }
    };


    @Override
    protected void initData() {
    }

    @Override
    public void onResume() {
        super.onResume();
        if (mContext != null) {
            getData();
        }
    }

    private void getData() {
        adapter.setData(SqlHelper.getHistory());

        if (adapter.getItemCount() == 0) {
            multiplestatusView.setViewState(MultiStateView.ViewState.EMPTY);
        } else {
            multiplestatusView.setViewState(MultiStateView.ViewState.CONTENT);
        }
    }

//    @OnClick({R.id.tv_sendcode})
//    public void onViewClicked(View view) {
//        switch (view.getId()) {
//            case R.id.tv_sendcode:
//                break;
//        }
//    }


}
